package com.lncd.backend.repository;

import com.lncd.backend.model.Location;
import com.lncd.backend.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
import java.util.Optional;

@Repository
public interface LocationRepository extends JpaRepository<Location, Long> {
    List<Location> findByUserOrderByTimestampDesc(User user);
    
    @Query("SELECT l FROM Location l WHERE l.user.id = :userId AND l.timestamp BETWEEN :startTime AND :endTime ORDER BY l.timestamp DESC")
    List<Location> findByUserIdAndTimestampBetween(Long userId, Date startTime, Date endTime);
    
    @Query("SELECT l FROM Location l WHERE l.user.id = :userId ORDER BY l.timestamp DESC LIMIT 1")
    Optional<Location> findLatestByUserId(Long userId);
} 